local shujian = fk.CreateSkill{
  name = "xiaobai__shujian"
}

Fk:loadTranslationTable{
  ["xiaobai__shujian"] = "疏谏",
  [":xiaobai__shujian"] = "当你成为<font color='red'>♥</font>牌、基本牌或你使用的牌的目标后，你可以令一名不为当前回合的角色摸一张牌，"..
    "若该牌：仅满足两项，你可以多选择一名角色；均满足，被选择的角色可改为回复1点体力。",

  ["#xiaobai__shujian"] = "疏谏：你可以令至多 %arg 名角色摸一张牌 %arg2",
  ["#xiaobai__shujian_recover"] = "或回复1点体力",
  ["#xiaobai__shujian_ask2recover"] = "疏谏：你可以回复1点体力，或点击取消摸一张牌",
  ["@xiaobai__shujian"] = "疏谏",

  ["$xiaobai__shujian1"] = "撤冗杂闲位，统为四职。",
  ["$xiaobai__shujian2"] = "为教化优良，见政而争。",
}

shujian:addEffect(fk.TargetConfirmed, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target == player and (
      data.card.suit == Card.Heart or data.card.type == Card.TypeBasic or data.from == player
    )
  end,
  on_cost = function (self, event, target, player, data)
    local num = 0
    local room = player.room
    if data.card.suit == Card.Heart then
      num = num + 1
    end
    if data.card.type == Card.TypeBasic then
      num = num + 1
    end
    if data.from == player then
      num = num + 1
    end
    local tos 
    if num == 1 then
      tos = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 2,
        targets = room:getOtherPlayers(room.current),
        skill_name = shujian.name,
        prompt = "#xiaobai__shujian:::".."1"..":"
      })
    elseif num == 2 then
      tos = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 2,
        targets = room:getOtherPlayers(room.current),
        skill_name = shujian.name,
        prompt = "#xiaobai__shujian:::".."2"..":"
      })
    else
      tos = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 2,
        targets = room:getOtherPlayers(room.current),
        skill_name = shujian.name,
        prompt = "#xiaobai__shujian:::".."1"..":".."#xiaobai__shujian_recover"
      })
    end
    if #tos > 0 then
      event:setCostData(self, {num = num, tos = tos})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cost_data = event:getCostData(self)
    room:setPlayerMark(player, "@xiaobai__shujian", cost_data.num)
    local targets = cost_data.tos ---@type ServerPlayer[]
    room:sortByAction(targets)
    table.forEach(targets, function (p)
      if cost_data.num < 3 or p:getLostHp() == 0 then
        p:drawCards(1, shujian.name)
        room:delay(100)
      else
        if room:askToSkillInvoke(p, {
          skill_name = shujian.name,
          prompt = "#xiaobai__shujian_ask2recover"
        }) then
          room:recover{
            who = p,
            num = 1,
            recoverBy = player,
            skillName = shujian.name,
          }
        else
          p:drawCards(1, shujian.name)
        end
      end
    end)
  end
})

return shujian